package it.gma.torero.operator;

import it.gma.torero.operand.Operand;
import it.gma.torero.operand.VariableBinder;

/**
 * <a href="http://en.wikipedia.org/wiki/Exclusive_or">Exclusive disjunction</a>
 * or exclusive or (/ˌɛks ˈɔr/) is a logical operation that outputs true
 * whenever both inputs differ (one is true, the other is false)
 * 
 * @author giordano
 * 
 */
public class XorOperator extends AbstractBooleanOperator {

	AndOperator xor;

	public XorOperator(Operand operand1, Operand operand2) {
		super(operand1, operand2);
		xor = new OrOperator(operand1, operand2).and(new AndOperator(operand1, operand2).not());
	}

	public boolean evaluate() {
		return xor.evaluate();
	}

	@Override
	public String toString() {
		return "(" + operand1 + " xor " + operand2 + ")";
	}

	@Override
	public void setContext(VariableBinder context) {
		super.setContext(context);
		xor.setContext(context);
	}
}
